package com.tianqu.tms.core.taglib;

import javax.servlet.jsp.tagext.TagSupport;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.security.AccessController;
import com.tianqu.tms.core.security.TmsUserProfile;


/**
 * 
 * @author liugang
 *
 */
public class MenuTagSupport extends TagSupport {
	
	// Resource Bundle
	public static final String MENURESOURCE = "com.tianqu.tms.web.resources.MenuResource";
	
	public static final String LOCALE_KEY = org.apache.struts.Globals.LOCALE_KEY;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1295875660638762863L;

	/**
	 * 判定用户是否有权限
	 * @param MenuBean
	 * @return
	 */
	protected boolean hasViewCompetence(MenuBean MenuBean) {
		if (MenuBean.isNeedsRole()){
			String funcId = MenuBean.getFunctionId();
			UserContext uc =
				(UserContext) pageContext.getSession().getAttribute(
					TmsAction.APPLICATION_USER_CONTEXT_KEY);
			TmsUserProfile userProfile = uc.getUserProfile();
			try {
				AccessController accessController = AccessController.getInstance();
				return accessController.checkPermission(userProfile,funcId);
			} catch (Exception e) {
				return false;
			}
		}
		return true;
	}
}
